<template>
	<view class="page">
		<!-- 收藏 -->
		<view class="navbar">
			共 <text>{{list.length}}</text> 词
		</view>
		
		<!-- <view class="list">
			<u-swipe-action>
				<u-swipe-action-item :options="options1" v-for="(item,i) in list" :key="item.id"
					@click="handleCollect($event,item)">
					<view class="item d_flex_b" @click="toInfo(item)">
						<view class="word">{{item.name}}</view>
						<view class="explain flex1" v-if="item.wordExplain">
							{{JSON.parse(item.wordExplain)[0].chinExplain}}
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
		</view> -->

		<view class="list">
			<uni-swipe-action>
				<uni-swipe-action-item :right-options="options1" v-for="(item,i) in list" :key="item.id"
					@click="handleCollect($event,item)">
					<view class="item d_flex_b" @click="toInfo(item)">
						<view class="word">{{item.name}}</view>
						<view class="explain flex1" v-if="item.wordExplain">
							{{JSON.parse(item.wordExplain)[0].chinExplain}}
						</view>
					</view>
				</uni-swipe-action-item>
			</uni-swipe-action>
		</view>

		<view class="zy-box" v-if="isShow">
			<view class="pop-box">
				<image src="/static/gg.png" mode=""></image>
				<view class="btn" @click="closeGuide">
					知道了
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
	
		data() {
			return {
				isShow: false,
				list: [],
				options1: [{
					text: '取消收藏',
					src: '/static/cc.png',
					style: {
						backgroundColor: '#FF7474',
						flexDirection: 'column',
						fontSize: '24rpx'
					}
				}],
				options2: [{
					text: '取消收藏',
					style: {
						backgroundColor: '#FF7474'
					}
				}],
			};
		},
		onLoad() {
			if (!uni.getStorageSync('isCollectShow')) {
				this.isShow = true;
			}
		},
		onShow() {
			this.getList();
		},
		methods: {
			closeGuide() {
				this.isShow = false;
				uni.setStorageSync('isCollectShow', true)
			},
			getList() {
				this.$http.get1('api/client/word/favorites').then(res => {
					if (res.code == 200) {
						this.list = res.data;
					}
				})
			},
			toInfo(item) {
				uni.navigateTo({
					url: '/pagesA/pages/test/explain?id=' + item.id + '&type=3'
				})
			},
			handleCollect(e, item) {
				this.$http.delete('api/client/word/removeFavoritesWord?wordId=' + item.id, {
					wordId: item.id,
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '操作成功'
						})
						this.getList();
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F2F3F8;
		box-sizing: border-box;
	}

	.navbar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		font-size: 22rpx;
		color: #333333;
		text-align: center;
		height: 96rpx;
		background: #F9FBFF;
		box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42, 65, 152, 0.05);
		line-height: 96rpx;
		position: fixed;
		z-index: 19;

		text {
			color: #5480F8;
			margin: 0 8rpx;
		}
	}

	.zy-box {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.3);
		z-index: 999;

		.pop-box {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			text-align: center;

			image {
				width: 364rpx;
				height: 226rpx;

			}

			.btn {
				margin-top: 22rpx;
				width: 626rpx;
				height: 90rpx;
				background: #5480F8;
				border-radius: 46rpx;
				text-align: center;
				line-height: 90rpx;
				color: #FFFFFF;
				font-size: 32rpx;
			}
		}
	}

	.u-swipe-action-item {
		margin-bottom: 20rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42, 65, 152, 0.05);
		border-radius: 20rpx 20rpx 20rpx 20rpx;
	}
	
	.uni-swipe{
		margin-bottom: 20rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42, 65, 152, 0.05);
		border-radius: 20rpx 20rpx 20rpx 20rpx;
	}

	.list {
		padding: 120rpx 32rpx 30rpx;

		.item {
			width: 686rpx;
			padding: 40rpx 30rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			// border:1rpx solid red;
			// margin-bottom: 20rpx;
			// box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42,65,152,0.05);
			// border-radius: 20rpx 20rpx 20rpx 20rpx;
			.word {
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
				width: 250rpx;
			}

			.explain {
				width: 300rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-size: 24rpx;
				font-weight: 400;
				color: #575A64;
				text-align: left;
				padding: 0 30rpx;
			}

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}
</style>